{if !isset($imdbsearch) || strlen($imdbsearch) == 0}
<nav>
	<ul>
		{if !isset($imdbresults)}
		<li>
			<div class="button">
				<div>
					<a href="javascript:void(0);" onclick="$('#submit').click(); return true;"><img src="{$tpl_include}images/icons/32x32/disk.png" alt="{$smarty.const.SAVE|htmlentities:3:'UTF-8'}" title="{$smarty.const.SAVE|htmlentities:3:'UTF-8'}"><br/>
					{$smarty.const.SAVE|htmlentities:3:'UTF-8'}</a>
				</div>
			</div>
		</li>
		{/if}
		
		{if isset($movie) && !isset($imdbmovie) && isset($movie->imdbid) && $movie->imdbid > 0}
		<li>
			<div class="button">
				<div>
					<a href="./?go=edit&id={$movie->id}&imdbid={$movie->imdbid}"><img src="{$tpl_include}images/icons/imdb.png" alt="{$smarty.const.UPDATE|htmlentities:3:'UTF-8'}" title="{$smarty.const.UPDATE|htmlentities:3:'UTF-8'}"><br/>
					{$smarty.const.UPDATE|htmlentities:3:'UTF-8'}</a>
				</div>
			</div>
		</li>
		{/if}
			
		{if !isset($imdbmovie) && isset($movie) && $movie->hasCover()}
		<li>	
			<div class="button">
				<div>
					<a href="javascript:void(0);" onclick="if(confirm('{$smarty.const.CONFIRM_REMOVE_COVER}')) location.href='./?go=deletecover&id={$movie->id}';"><img src="{$tpl_include}images/icons/32x32/picture_delete.png" alt="{$smarty.const.REMOVE_COVER|htmlentities:3:'UTF-8'}" title="{$smarty.const.REMOVE_COVER|htmlentities:3:'UTF-8'}"><br/>
					{$smarty.const.REMOVE_COVER|htmlentities:3:'UTF-8'}</a>
				</div>
			</div>
		</li>
		{/if}
			
		{if isset($movie) && !isset($imdbmovie)}
		<li>
			<div class="button">
				<div>
					<a href="javascript:void(0);" onclick="if(confirm('{$smarty.const.CONFIRM_REMOVE}')) location.href='./?go=delete&id={$movie->id}';"><img src="{$tpl_include}images/icons/32x32/delete.png" alt="{$smarty.const.REMOVE|htmlentities:3:'UTF-8'}" title="{$smarty.const.REMOVE|htmlentities:3:'UTF-8'}"><br/>
					{$smarty.const.REMOVE|htmlentities:3:'UTF-8'}</a>
				</div>
			</div>
		</li>
		{/if}
	</ul>
</nav>
{/if}

<div class="content">
	{if !isset($movie)}
	{* Search IMDb movie information for new movies *}
	<form id="imdbsearchform">
		<h2>{$smarty.const.ADD_FROM_IMDB|htmlentities:3:'UTF-8'}</h2>
		<table>
			<tr>
				<td>
					<input type="hidden" name="go" value="add">
					<input type="text" id="imdbsearch" name="imdbsearch" value="{if isset($imdbsearch)}{$imdbsearch|htmlentities:3:'UTF-8'}{/if}" class="required">
				</td>
			</tr>
			<tr>
				<td>
					<input type="submit" value="{$smarty.const.SEARCH|htmlentities:3:'UTF-8'}">
				</td>
			</tr>
		</table>
	</form>
	{/if}
	
	{if isset($imdbresults) && $imdbresults|@count > 0}
	{* Search results from IMDb *}
	<div>
		<h3>{$smarty.const.RESULTS_FROM_IMDB|htmlentities:3:'UTF-8'}</h3>
		<table class="imdbmovies hover">
			{section name=r loop=$imdbresults}
			<tr class="imdbresult">
				<td class="imdb">
					<a href="http://www.imdb.com/title/tt{$imdbresults[r]->imdbid()}/" target="_blank"><img src="{$tpl_include}images/icons/imdb.png" alt="{$smarty.const.VISIT_IMDB|htmlentities:3:'UTF-8'}" title="{$smarty.const.VISIT_IMDB|htmlentities:3:'UTF-8'}"></a>
				</td>
				<td class="title{if $imdbresults[r]->known} known{/if}" onclick="location.href='./?go=add&imdbid={$imdbresults[r]->imdbid()}';">
					<a href="./?go=add&imdbid={$imdbresults[r]->imdbid()}">{$imdbresults[r]->title()}</a>
				</td>
				<td class="year{if $imdbresults[r]->known} known{/if}" onclick="location.href='./?go=add&imdbid={$imdbresults[r]->imdbid()}';">
					{$imdbresults[r]->year()}
				</td>
			</tr>
			{/section}
		</table>
	</div>
	{elseif isset($imdbsearch) && strlen($imdbsearch) > 0}
	{* No results found on IMDb *}
	<div>
		{$smarty.const.NO_RESULTS_FOUND|htmlentities:3:'UTF-8'}
	</div>
	{else}
	{* Show movie information *}
	<script>
		$(document).ready(function() {
			var availableTags = [
				{if $movieformats|@count == 0}'{$smarty.const.DVD|htmlentities:3:'UTF-8'}',{/if}
	    		{section name=f loop=$movieformats}'{$movieformats[f]|htmlentities:3:'UTF-8'}',{/section}
	    	];
			$("#formats").autocomplete({
				source: availableTags
			});
	        
			// remote, email, url, date, dateISO, digits, creditcard, equalTo, accept, maxlength, minlength, rangelength, range, max, min
			$.validator.messages["required"] = "{$smarty.const.VALIDATOR_REQUIRED|htmlentities:3:'UTF-8'}";
			$.validator.messages["number"] = "{$smarty.const.VALIDATOR_NUMBER|htmlentities:3:'UTF-8'}";
			$.validator.messages["digits"] = "{$smarty.const.VALIDATOR_DIGITS|htmlentities:3:'UTF-8'}";
			$.validator.messages["email"] = "{$smarty.const.VALIDATOR_EMAIL|htmlentities:3:'UTF-8'}";
			$.validator.messages["url"] = "{$smarty.const.VALIDATOR_URL|htmlentities:3:'UTF-8'}";
			$.validator.messages["date"] = "{$smarty.const.VALIDATOR_DATE|htmlentities:3:'UTF-8'}";
			$.validator.messages["accept"] = "{$smarty.const.VALIDATOR_ACCEPT_JPG|htmlentities:3:'UTF-8'}";
			$("#imdbsearchform").validate();
			$("#imdbsearch").select();
			$("#updateform").validate({
			  rules: {
				    cover: {
				      required: false,
				      accept: "jpe?g",
					}
				}
			});
			$("#updateform").valid();
			
			{if $autoupdate}
			$("#submit").click();
			{/if}
		});
	</script>
	
	<div class="addmovie">
		<h2>{$smarty.const.MOVIE_INFORMATION|htmlentities:3:'UTF-8'}</h2>
		
		<div class="photo">
			{if isset($imdbmovie) && $imdbmovie->photo()}
			<img src="{$imdbmovie->photo()}" alt="{$movie->name|htmlentities:3:'UTF-8'}" title="{$movie->name|htmlentities:3:'UTF-8'}">
			{elseif isset($movie) && $movie->hasPhoto()}
			<img src="{$movie->photo()}" alt="{$movie->name|htmlentities:3:'UTF-8'}" title="{$movie->name|htmlentities:3:'UTF-8'}">
			{elseif isset($movie) && $movie->hasCover()}
			<img src="{$movie->cover()}" alt="{$movie->name|htmlentities:3:'UTF-8'}" title="{$movie->name|htmlentities:3:'UTF-8'}">
			{/if}
		</div>
		
		<form id="updateform" method="POST" action="./?go={if !isset($movie) || $movie->id == 0}add{else}edit&id={$movie->id}{/if}" enctype="multipart/form-data">
			<table>		
				<tr>
					<td width="200">{$smarty.const.IMDB_NUMBER|htmlentities:3:'UTF-8'}</td>
					<td><input type="text" name="imdbid" value="{if isset($movie)}{$movie->imdbid|htmlentities:3:'UTF-8'}{/if}" class="digits"></td>
				</tr>
				<tr>
					<td>{$smarty.const.TITLE|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="text" name="name" value="{if isset($movie)}{$movie->name|htmlentities:3:'UTF-8'}{/if}" class="required">
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.AKA_TITLES|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="aka">{if isset($movie)}{$movie->aka|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.YEAR|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="text" name="year" value="{if isset($movie)}{$movie->year|htmlentities:3:'UTF-8'}{/if}" class="required digits">
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.DURATION_MINUTES|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="text" name="duration" value="{if isset($movie) && $movie->duration != 0}{$movie->duration|htmlentities:3:'UTF-8'}{/if}" class="digits">
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.RATING|htmlentities:3:'UTF-8'}</td>
					<td><input type="text" name="rating" value="{if isset($movie) && $movie->rating != 0}{$movie->rating|htmlentities:3:'UTF-8'}{/if}" class="number"></td>
				</tr>
				<tr>
					<td>{$smarty.const.FORMAT|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="text" id="formats" name="format" value="{if isset($movie) && isset($movie->format)}{$movie->format|htmlentities:3:'UTF-8'}{else}{$smarty.const.DVD|htmlentities:3:'UTF-8'}{/if}" class="required" autocomplete="off">
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.I_OWN_THIS_MOVIE|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="radio" name="own" id="own_yes" value="1"{if !isset($movie) || $movie->own} checked{/if}><label for="own_yes">{$smarty.const.YES|htmlentities:3:'UTF-8'}</label>
						<input type="radio" name="own" id="own_no" value="0"{if isset($movie) && !$movie->own} checked{/if}><label for="own_no">{$smarty.const.NO|htmlentities:3:'UTF-8'}</label>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.I_HAVE_SEEN_THIS_MOVIE|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="radio" name="seen" id="seen_yes" value="1"{if !isset($movie) || $movie->seen} checked{/if}><label for="seen_yes">{$smarty.const.YES|htmlentities:3:'UTF-8'}</label>
						<input type="radio" name="seen" id="seen_no" value="0"{if isset($movie) && !$movie->seen} checked{/if}><label for="seen_no">{$smarty.const.NO|htmlentities:3:'UTF-8'}</label>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.LOANED_OUT|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="radio" name="loaned" id="loaned_yes" value="1" onclick="$('#loandate').show(); $('#loanname').show(); $('#loanname input').focus();"{if isset($movie) && $movie->loaned} checked{/if}><label for="loaned_yes">{$smarty.const.YES|htmlentities:3:'UTF-8'}</label>
						<input type="radio" name="loaned" id="loaned_no" value="0" onclick="$('#loandate').hide(); $('#loanname').hide();"{if !isset($movie) || !$movie->loaned} checked{/if}><label for="loaned_no">{$smarty.const.NO|htmlentities:3:'UTF-8'}</label>
					</td>
				</tr>
				<tr id="loanname"{if !isset($movie) || !$movie->loaned} class="hide"{/if}>
					<td>{$smarty.const.LOANED_OUT_TO|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="text" name="loanname" value="{if isset($movie)}{$movie->loanname|htmlentities:3:'UTF-8'}{/if}">
					</td>
				</tr>
				<tr id="loandate"{if !isset($movie) || !$movie->loaned} class="hide"{/if}>
					<td>{$smarty.const.LOANED_OUT_SINCE|htmlentities:3:'UTF-8'}</td>
					<td>
						<input type="text" name="loandate" value="{if isset($movie) && $movie->loandate != '0000-00-00'}{$movie->loandate|htmlentities:3:'UTF-8'}{else}{$smarty.now|date_format:"%Y-%m-%d"}{/if}" class="date">
					</td>
				</tr>
				<tr>
					<td>
						{$smarty.const.COVER|htmlentities:3:'UTF-8'}
						<a href="http://www.cdcovers.cc/search/dvd/{if isset($movie)}{$movie->name|replace:" ":"-"|htmlentities:3:'UTF-8'}{/if}" target="_blank" class="right"><img height="16" src="{$tpl_include}images/icons/16x16/magnifier.png" alt="{$smarty.const.SEARCH_FOR_COVER|htmlentities:3:'UTF-8'}" title="{$smarty.const.SEARCH_FOR_COVER|htmlentities:3:'UTF-8'}"></a>
					</td>
					<td>
						<input type="file" id="cover" name="cover" size="30">
					</td>
				</tr>
				<tr>
					<td>
						{$smarty.const.TRAILER_URL|htmlentities:3:'UTF-8'}
						<a href="http://www.youtube.com/results?search_query={if isset($movie)}{$movie->name|urlencode}+{/if}trailer" target="_blank" class="right"><img height="16" src="{$tpl_include}images/icons/16x16/magnifier.png" alt="{$smarty.const.SEARCH_FOR_TRAILER|htmlentities:3:'UTF-8'}" title="{$smarty.const.SEARCH_FOR_TRAILER|htmlentities:3:'UTF-8'}"></a>
					</td>
					<td>
						<input type="text" name="trailer" value="{if isset($movie)}{$movie->trailer|htmlentities:3:'UTF-8'}{/if}" class="url">
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.PERSONAL_NOTES|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="notes">{if isset($movie)}{$movie->notes|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.TAGLINES|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="taglines">{if isset($movie)}{$movie->taglines|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.PLOT_OUTLINE|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="plotoutline">{if isset($movie)}{$movie->plotoutline|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.PLOTS|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="plots">{if isset($movie)}{$movie->plots|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.LANGUAGES|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="languages" id="text_languages_0" class="textarea">{if isset($movie)}{$movie->languages|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.SUBTITLES|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="subtitles">{if isset($movie)}{$movie->subtitles|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.AUDIO|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="audio">{if isset($movie)}{$movie->audio|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.VIDEO|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="video">{if isset($movie)}{$movie->video|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.COUNTRY|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="country">{if isset($movie)}{$movie->country|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.GENRES|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="genres">{if isset($movie)}{$movie->genres|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.DIRECTOR|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="director">{if isset($movie)}{$movie->director|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.WRITER|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="writer">{if isset($movie)}{$movie->writer|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.PRODUCER|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="producer">{if isset($movie)}{$movie->producer|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.MUSIC|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="music">{if isset($movie)}{$movie->music|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>{$smarty.const.CAST|htmlentities:3:'UTF-8'}</td>
					<td>
						<textarea name="cast">{if isset($movie)}{$movie->cast|htmlentities:3:'UTF-8'}{/if}</textarea>
					</td>
				</tr>
				<tr>
					<td>
						<input type="hidden" name="autoupdate" value="{$autoupdate}">
						<input type="hidden" name="movieid" value="{if isset($movie)}{$movie->id}{/if}">
					</td>
					<td><input type="submit" id="submit" name="submit" value="{$smarty.const.SAVE|htmlentities:3:'UTF-8'}"></td>
				</tr>
			</table>
		</form>
	</div>
	
	{if $autoupdate}
	<div class="autoupdate">
		<div class="text">
			<p>{$smarty.const.AUTOUPDATE_INFO|htmlentities:3:'UTF-8'}</p>
			<p>&nbsp;</p>
			<div class="button">
				<div>
					<a href="./"><img src="{$tpl_include}images/icons/32x32/stop.png" alt="{$smarty.const.STOP_UPDATE|htmlentities:3:'UTF-8'}" title="{$smarty.const.STOP_UPDATE|htmlentities:3:'UTF-8'}"><br/>
					{$smarty.const.STOP_UPDATE|htmlentities:3:'UTF-8'}</a>
				</div>
			</div>
		</div>
	</div>
	{/if}
	
	{/if}
</div>